package com.june.junemplayer.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

import com.june.junemplayer.pojo.Song;

public class OverlayWindowService extends Service{

    private OverlayWindowView mOverlayWindow;
    private IBinder mServiceBinder=new OverlayWindowServiceBinder();

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.d("JuneProcedure", getTag() + "----onBind");
        return mServiceBinder;
    }

    public void PlaySong(Song song) {
        mOverlayWindow.PlaySong(song);
    }

    public class OverlayWindowServiceBinder extends Binder {
        public OverlayWindowService getService() {
            return OverlayWindowService.this;
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("JuneProcedure", getTag() + "----onCreate");
        if (mOverlayWindow == null) {
           mOverlayWindow=new OverlayWindowView(this);
//           mOverlayWindow.show();
        }
    }

    public void changeStatus(OverlayWindowView.OverlayWindowBallStatus status){
        Log.d("JuneOperation", getTag() + "----changeStatus");
        switch (status){
            case INACTIVE:
                if (mOverlayWindow != null && mOverlayWindow.mStatus == OverlayWindowView.OverlayWindowBallStatus.GONE) {
                    mOverlayWindow.show();
                }
                break;
            case GONE:
                if (mOverlayWindow != null && mOverlayWindow.mStatus != OverlayWindowView.OverlayWindowBallStatus.GONE) {
                    mOverlayWindow.hide();
                }
                break;
        }
    }

    private String getTag(){
        return "OverlayWindowService";
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("JuneProcedure", getTag() + "----onDestroy");
    }
}


